package com.mall4jcola.cloud.auth.executor;

import cn.dev33.satoken.spring.SpringMVCUtil;
import cn.hutool.extra.servlet.ServletUtil;
import com.alibaba.cola.dto.Response;
import com.mall4jcola.cloud.auth.gateway.UserAuthsChangeGateway;
import com.mall4jcola.cloud.auth.model.UserAuthEntity;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 用户登录信息更新执行器
 * 如登录时间,登录ip等
 * @author hmxchen
 *
 */
@Component
@AllArgsConstructor
public class UserLoginInfoUpdateCmdExe {

    private final UserAuthsChangeGateway userAuthsChangeGateway;
    public Response execute(Long uaId) {
        UserAuthEntity userAuthEntity = new UserAuthEntity();
        userAuthEntity.setUaId(uaId);
        userAuthEntity.setLastTime(new Date());
        userAuthEntity.setLastIp(ServletUtil.getClientIP(SpringMVCUtil.getRequest(), null));
        userAuthsChangeGateway.updateAuthInfo(userAuthEntity);
        return Response.buildSuccess();
    }
}
